Skip to content

Improve dynamic terminal selection with AJAX loading#310

Open
TLabutis wants to merge 1 commit intorelease-2.0.3from
INTERNAL/terminal-selection-improvements
Open

Improve dynamic terminal selection with AJAX loading#310
TLabutis wants to merge 1 commit intorelease-2.0.3from
INTERNAL/terminal-selection-improvements

Conversation

@TLabutis
Copy link

Self-Checks

  • I have performed a self-review of my code.
  • I have updated/added necessary technical documentation in the README file.

JIRA task link

Summary

QA Checklist Labels

  • Bug fix?
  • New feature?
  • Improvement?
  • Technical debt?
  • Reusable?
  • Covered by tests?

QA Checklist

Additional Context

Frontend Changes

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @TLabutis, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the configuration experience for SaferPay terminals within the admin panel. It transitions the terminal selection process from a static list to a dynamic, AJAX-driven mechanism, enabling administrators to fetch and select terminals in real-time. The addition of a manual input field and a refresh button further improves flexibility and usability, making the terminal setup more robust and user-friendly.

Highlights

  • Dynamic Terminal Loading: Implemented AJAX-based dynamic loading of SaferPay terminals in the admin settings, allowing real-time fetching of available terminals based on provided credentials.
  • Manual Terminal Input: Introduced a manual input option for terminal IDs, providing flexibility for administrators to enter terminal IDs directly if dynamic loading is not preferred or fails.
  • Enhanced User Interface: Improved the UI for terminal selection with a dedicated refresh button and more informative help text, enhancing the overall user experience during configuration.
  • Backend API for Terminals: Added a new AJAX endpoint in the admin controller to handle requests for fetching terminals, including credential validation and robust error handling.
  • Refactored Terminal Parsing: Adjusted the terminal parsing logic in the service layer to ensure unique terminal IDs are handled correctly and the data structure is consistent for frontend consumption.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant improvement by dynamically loading SaferPay terminals via AJAX, enhancing the user experience in the admin settings. The implementation correctly uses debouncing for performance and provides good UI feedback. However, there are several critical issues that need to be addressed before merging. A fatal error will occur when fetching terminals due to a method signature mismatch between the controller and the service. The JavaScript file contains leftover debugging code, including an alert() that will block the UI, and a bug in the form submission logic. I've left detailed comments on these points.

/** @var SaferPayTerminalService $terminalService */
$terminalService = $this->module->getService(SaferPayTerminalService::class);

$terminals = $terminalService->getAvailableTerminals($customerId, $username, $password, $isTestMode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The getAvailableTerminals method is called with four arguments ($customerId, $username, $password, $isTestMode), but its definition in SaferPayTerminalService only accepts one optional argument ($customerId). This will cause a fatal error.

The SaferPayTerminalService::getAvailableTerminals method needs to be updated to accept these new parameters and use them to make the API request with the correct credentials and environment, instead of relying on the stored configuration values.

console.log('[DEBUG] Making AJAX request with params:', Object.assign({}, params, {password: '***'}));
// #endregion

alert('Customer ID before AJAX: ' + customerId); // Temporary debug alert
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This alert() is clearly for debugging and must be removed. It will block the UI for administrators and provides a poor user experience.


$('form').on('submit', function() {
if ($manualInput.val() && !$select.val()) {
var manualValue = $(this).val();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There is a bug in the form submit handler. $(this).val() is being used to get the value of the manual input, but this refers to the form element, not the input. This will not retrieve the correct value. You should use $manualInput.val() instead.

Suggested change
var manualValue = $(this).val();
var manualValue = $manualInput.val();

Comment on lines +24 to +26
// #region agent log
console.log('[DEBUG] saferpay_settings.js loaded');
// #endregion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This file contains multiple debugging regions with console.log and console.error statements (e.g., lines 24-26, 41-43, 53-55, 111-113, 124-126, 136-138, 170-172). These should be removed from the production code to avoid cluttering the browser console and for cleaner code.

class="saferpay-terminal-manual-input form-control fixed-width-xl"
placeholder="{l s='Or enter Terminal ID manually' mod='saferpayofficial'}"
value="{if (!isset($field['terminals']) || count($field['terminals']) == 0) && $field['value']}{$field['value']|escape:'htmlall':'UTF-8'}{/if}"
style="margin-top: 5px; {if isset($field['terminals']) && count($field['terminals']) > 0}display: none;{/if}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using inline styles for conditional display logic is not ideal as it mixes presentation with structure. It's better to toggle a CSS class. PrestaShop/Bootstrap provides utility classes like hidden or d-none for this purpose. This improves code readability and maintainability.

For example:

class="... {if isset($field['terminals']) && count($field['terminals']) > 0}hidden{/if}"
style="margin-top: 5px;"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant